package leetCode.firstWeek;

public class Code_14 {
    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) {
            return "";
        }
        int min_length = Integer.MAX_VALUE;
        for (String s : strs) {
            if (min_length > s.length()) {
                min_length = s.length();
            }
        }
        for (int i = 0; i < min_length; i++) {
            for (int j = 0; j < strs.length; j++) {
                if (strs[0].charAt(i) != strs[j].charAt(i)) {
                    return strs[0].substring(0, i);
                }
            }
            if (i == min_length - 1) {
                return strs[0].substring(0, min_length);
            }
        }
        return "";
    }
}
